/*
 * #depends subsonic-application.js
 */
Ext.regController('Ext.ux.mattgoldspink.subsonic.controllers.MusicStore', {
    initialise: function(){
        this.store = Ext.StoreMgr.get('Ext.ux.mattgoldspink.subsonic.stores.MusicStore');
        var params = {};
        Ext.apply(params, Ext.ux.mattgoldspink.subsonic.LoginDetails);
        this.store.getProxy().extraParams = params;
		this.task = new Ext.util.DelayedTask(this.doDispatch, this);
		this.doDispatch();
    },
	doDispatch: function() {
		var url, model;
		url = window.location.hash.substring(1);
		if (Ext.isEmpty(url)) {
			model = Ext.StoreMgr.get('Ext.ux.mattgoldspink.subsonic.stores.LeftMenuStore').first();
			if (!Ext.isEmpty(model) && model.getId() && model.get('iconCls') === 'music') {
				url = '/musicFolder/' + model.getId();
			}
		}
		if (!Ext.isEmpty(url)) {
			Ext.dispatch({
				controller: 'Ext.ux.mattgoldspink.subsonic.controllers.SongView',
				action: 'loadFolder',
				initComplete: true,
				historyUrl: url
			});
			delete this.task;
		} else {
			this.task.delay(50);
		}
	}
});
